<?php
$callback = htmlentities($_GET['callback']);

date_default_timezone_set("Asia/ShangHai");
include("config.php");
$Connect = new PDO('mysql:host='.$db['host'].';dbname='.$db['database'], $db['user'], $db['pass']);
$Connect->query("set names 'utf8'");


$type = $_GET['type'];
if($type == 'hot') {
	$order = " order by `face_download` desc ";
} else if($type == 'new') {
	$order = " order by `created` desc ";
} else {
	$order = '';
}
$page = (int)$_GET['page'];
$perpage = (int)$_GET['perpage'];
$page = $page ?$page:1;
$perpage = $perpage?$perpage:10;
	$mOffset = ($page-1) * $perpage ;
$sql = "select face_id,face_name,source,content,type from `face_resource` ".$order." limit ".$mOffset.",".$perpage;
//echo $sql;
//$sql_total = "select count(1) as total from `face_resource` where `category_id` = '".$category_id."'";
$exec = $Connect->query($sql);
$result  = $exec->fetchAll(PDO::FETCH_ASSOC);

//$exec = $Connect->query($sql_total);
$total = 20;
$ret = array("data"=>$result,"total"=>$total,"perpage"=>$perpage,"page"=>$page);
echo $callback."(".json_encode($ret).")";

?>